// import { login, logout, getInfo } from '@/api/user'
import { getToken, setToken, removeToken } from '@/utils/auth'
// import { resetRouter } from '@/router'
import { loginAPI, suerInfoAPI, informationAPI } from '@/api'
import { Message } from 'element-ui'
// 数据
const state = {
  token: getToken() || null,
  // 储存用户信息
  userInfo: null
}
// 方法
const mutations = {
  setToken(state, payload) {
    state.token = payload.token
  },
  userInfo(state, payload) {
    state.userInfo = payload
  }
}
// 发请求
const actions = {
  // 登录
  async loginAction(context, payload) {
    const token = await loginAPI(payload)
    setToken(token)
    context.commit('setToken', { token })
  },
  // 获取用户信息
  async getUserInfo(context) {
    const res = await suerInfoAPI()
    // console.log(res)
    const res1 = await informationAPI(res.userId)
    // console.log(res1)
    context.commit('userInfo', { ...res, ...res1 })
  },
  // 退出
  logout(context) {
    context.commit('setToken', { token: null })
    removeToken()

    context.commit('userInfo', null)
  }
  // 获取员工基本信息
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
